﻿using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace TomNet.Swagger
{
    public static class ApplicationBuilderExtensions
    {
        public static void UseApiSwagger(this IApplicationBuilder app)
        {
            var _options = app.ApplicationServices.GetTomNetOptions();

            if (!_options.Swagger.Enabled) return;

            app.UseSwagger().UseSwaggerUI(options =>
            {
                string url = _options.Swagger.Url;
                string title = _options.Swagger.Title;
                int version = _options.Swagger.Version;
                options.SwaggerEndpoint(url, $"{title} V{version}");
                options.DocumentTitle = title;
            });
        }
    }
}
